﻿using System;
using System.Collections.Generic;
using System.Text;
using FunctionalCLR.Core;
using FunctionalCLR.Shell;

namespace Zove.Shell.Core.Function.Matrix
{
    public class DeterminantNode : ContextFuncNode
    {

        public DeterminantNode()
            : base()
        {
            base.Value = "det";
        }

        public override object Evaluate()
        {
            if (Parameters.Count < 0)
            {
                throw new ArgumentException(
                    "usage: det(matrix)");
            }

            double[,] m = null;
            DhbMatrixAlgebra.Matrix matrix = null;

            List<object> mat = Parameters[0].Evaluate() as List<object>;
            m = MatrixUtils.GetMatrix(mat);

            matrix = new DhbMatrixAlgebra.Matrix(m);

            return matrix.Determinant().ToString();
        }
    }
}
